<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>敏感词</div>
    <div class="word">
        youarefoolguy
    </div>
</body>
<script>
    var badwords = ["bad", "fool"];
    var wordDom = document.querySelector(".word");
    var text = wordDom.innerText;
    console.log(text.includes("fool"))
    for(var i = 0; i < badwords.length; i++){
        let index = badwords.indexOf(badwords[i]);
        console.log(index);
        while(text.indexOf(badwords[i]) != -1){
            text = text.replace(badwords[i], "****")
            console.log(text)
            wordDom.innerText = text
        }
        
    }
</script>
</html>